package com.example.s.fragment.main_child_fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.s.R;
import com.example.s.adapter.InnerHolder;
import com.example.s.adapter.MyFragmentPagerAdapter;
import com.example.s.adapter.MyRecyclerViewAdapter;
import com.example.s.bean.Follower;
import com.example.s.bean.FollowerContent;
import com.example.s.fragment.BaseFragment;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class FollowFragment extends BaseFragment {
    private RecyclerView rvFollower;
    private RecyclerView rvFollowerContent;
    private MyRecyclerViewAdapter<Follower> mFollowerMyRecyclerViewAdapter;
    private List<Follower> mFollowerList = new ArrayList<>();
    private MyRecyclerViewAdapter<FollowerContent> mFollowerContentMyRecyclerViewAdapter;
    private List<FollowerContent> mFollowerContentList = new ArrayList<>();


    @Override
    public int getLayoutId() {
        return R.layout.fragment_follow;
    }

    @Override
    public void initView(View view) {

        rvFollower = (RecyclerView)findViewById(R.id.rv_follower);
        rvFollowerContent = (RecyclerView) findViewById(R.id.rv_follower_content);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
//        "大花","顾天云","灰灰","曙光","等一个你","xuanni","触景生情",
        mFollowerList.add(new Follower(R.drawable.yywtx6,"大花"));
        mFollowerList.add(new Follower(R.drawable.yywtx12,"顾天云"));
        mFollowerList.add(new Follower(R.drawable.yywtx18,"灰灰"));
        mFollowerList.add(new Follower(R.drawable.yywtx24,"等一个你"));
        mFollowerList.add(new Follower(R.drawable.yywtx30,"xuanni"));
        mFollowerList.add(new Follower(R.drawable.yywtx23,"触景生情"));
        rvFollower.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false));
        rvFollower.setAdapter(mFollowerMyRecyclerViewAdapter = new MyRecyclerViewAdapter<Follower>(mFollowerList,R.layout.follow_recycler_follwer_item) {
            @Override
            public void handleData(InnerHolder holder, Follower item) {
                holder.setText(R.id.name,item.getName());
                holder.setSrcResource(R.id.headphoto,item.getHeadPhoto());
            }
        });


        setFollwerContentData();
        rvFollowerContent.setLayoutManager(new LinearLayoutManager(getContext()));
        rvFollowerContent.setAdapter(mFollowerContentMyRecyclerViewAdapter = new MyRecyclerViewAdapter<FollowerContent>(mFollowerContentList,R.layout.follow_recycler_follwercontent_item) {
            @Override
            public void handleData(InnerHolder holder, FollowerContent item) {

                holder.setSrcResource(R.id.headphoto,item.getHeadphoto());
                holder.setText(R.id.name,item.getName());
                holder.setText(R.id.realseTime,item.getReleaseTime());
                holder.setText(R.id.likes,String.valueOf(item.getLikes()));
                holder.setText(R.id.title,item.getTitle());
                holder.setText(R.id.content,item.getContent());
                holder.setText(R.id.contentNums,1+"/"+item.getContentPhotoList().size());
                holder.setText(R.id.email,item.getEmail()                 );
                Banner banner = holder.getView(R.id.contentBanner);
                banner.setAdapter(new BannerImageAdapter<Integer>(item.getContentPhotoList()) {
                    @Override
                    public void onBindView(BannerImageHolder holder, Integer data, int position, int size) {
                        holder.imageView.setImageResource(data);
                    }
                })
                .addOnPageChangeListener(new OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                        holder.setText(R.id.contentNums,position+1+"/"+item.getContentPhotoList().size());
                    }

                    @Override
                    public void onPageSelected(int position) {

                    }

                    @Override
                    public void onPageScrollStateChanged(int state) {

                    }
                }).addBannerLifecycleObserver(getActivity());
//                headphoto = (CircleImageView) findViewById(R.id.headphoto);
//                name = (TextView) findViewById(R.id.name);
//                realseTime = (TextView) findViewById(R.id.realseTime);
//                contact = (ImageView) findViewById(R.id.contact);
//                share = (ImageView) findViewById(R.id.share);
//                contentBanner = (Banner) findViewById(R.id.contentBanner);
//                contentNums = (TextView) findViewById(R.id.contentNums);
//                like = (ImageView) findViewById(R.id.like);
//                likes = (TextView) findViewById(R.id.likes);
//                collection = (ImageView) findViewById(R.id.collection);
//                chat = (ImageView) findViewById(R.id.chat);
//                title = (TextView) findViewById(R.id.title);
//                content = (TextView) findViewById(R.id.content);

            }
        });

    }



    private void setFollwerContentData() {
        List<Integer> contentDataList = new ArrayList<>();
        contentDataList.add(R.drawable.yyw_xq1);
        contentDataList.add(R.drawable.yyw_xq2);
        contentDataList.add(R.drawable.yyw_xq3);
        FollowerContent followerContent = new FollowerContent(R.mipmap.home_page_headphoto, "养业文", "2天前", 32, "光影氛围", "一张表达人物故事的照片", "1611993222@qq.com",
                contentDataList);
        mFollowerContentList.add(followerContent);
    }

}
